//
// Created by Administrator on 2023/8/1.
//
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;


class Solution {
public:
    vector<vector<int>> mergeSimilarItems(vector<vector<int>> &items1, vector<vector<int>> &items2) {
        map<int,int>counter;
        for(auto &item:items1){
            counter[item[0]]+=item[1];
        }
        for(auto &item:items2){
            counter[item[0]]+=item[1];
        }
        vector<vector<int>>result;
        for(auto &item:counter){
            result.push_back({item.first,item.second});
        }
        return result;
    }
};

int main(int argc, char *argv[]) {
    Solution s;
    vector<vector<int>> items1 = {{1, 1},
                                  {4, 5},
                                  {3, 8}};
    vector<vector<int>> items2 = {{3, 1},
                                  {1, 5}};
    vector<vector<int>> result = s.mergeSimilarItems(items1, items2);
    // 打印result所有元素
    for (auto & i : result) {
        cout <<  "[" << i[0] << "," << i[1] << "]" << endl;
    }
    return 0;
}